package com.hst.capacity.infra.persistence.jpa.setting.price;

import com.hst.capacity.domain.model.entity.setting.price.NewExpressPriceEntity;
import com.hst.capacity.domain.model.entity.setting.price.NewStationPriceEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface NewExpressPriceRepository extends JpaRepository<NewExpressPriceEntity, String> {

    @Query("select t from NewExpressPriceEntity t where t.idFranchisee=:idFranchisee")
    Page<NewExpressPriceEntity> findByIdFranchisee(String idFranchisee, PageRequest pageRequest);

    /**
     * 通过地区查找站点价格
     * @param regionCode
     * @return
     */
    @Query("select o " +
            "from NewExpressPriceEntity o " +
            "where o.regionCode =:regionCode ")
    List<NewExpressPriceEntity> findByRegionCode(@Param("regionCode")String regionCode);

    NewExpressPriceEntity findByIdServicePriceType(String idPrice);

    /**
     * 通过地区查找站点价格
     * @param regionCode
     * @return
     */
    @Query("select o " +
            "from NewExpressPriceEntity o " +
            "where o.idFranchisee =:idFranchisee " +
            "and o.regionCode =:regionCode " +
            "and o.idServiceType =:idServiceType " +
            "and o.idVehicleType =:idVehicleType " )
    NewExpressPriceEntity findAllByRegionCode(@Param("idFranchisee")String idFranchisee, @Param("regionCode")String regionCode, @Param("idServiceType")int idServiceType, @Param("idVehicleType")int idVehicleType);

    /**
     * 通过地区查找站点价格
     * @param regionCode
     * @return
     */
    @Query("select t " +
            "from NewExpressPriceEntity t " +
            "where t.idFranchisee =:idFranchisee " +
            "and t.regionCode =:regionCode " +
            "and t.idServiceType =:idServiceType " +
            "and t.idVehicleType =:idVehicleType " +
            "and t.channel =:channel " )
    NewExpressPriceEntity findByRegionCode(@Param("idFranchisee")String idFranchisee, @Param("regionCode")String regionCode, @Param("idServiceType")int idServiceType, @Param("idVehicleType")int idVehicleType, @Param("channel")String channel);

    /**
     * 通过地区查找站点价格
     * @param regionCode
     * @return
     */
    @Query("select t " +
            "from NewExpressPriceEntity t " +
            "where t.idFranchisee =:idFranchisee " +
            "and t.regionCode =:regionCode " +
            "and t.idServiceType =:idServiceType " +
            "and t.idVehicleType =:idVehicleType " +
            "and t.channel =:channel " +
            "and t.status = 1" )
    NewExpressPriceEntity findOnlineByRegionCode(@Param("idFranchisee")String idFranchisee, @Param("regionCode")String regionCode, @Param("idServiceType")int idServiceType, @Param("idVehicleType")int idVehicleType, @Param("channel")String channel);

    /**
     * 通过地区查找站点价格
     * @param idFranchisee
     * @return
     */
    @Query("select o " +
            "from NewExpressPriceEntity o " +
            "where o.idFranchisee =:idFranchisee " +
            "and o.idBrandHolder =:idBrandHolder " +
            "and o.status = 1")
    List<NewExpressPriceEntity> findByIdFranchisee(@Param("idFranchisee")String idFranchisee);

    @Query("select o " +
            "from NewExpressPriceEntity o " +
            "where o.idServicePriceType = :idPrice")
    NewExpressPriceEntity findMarkupByIdServicePriceType(@Param("idPrice") String idPrice);

}